<script type="text/javascript">
$(document).ready(function() {
	setTimeout(function(){
	  $("#kotak").fadeOut("slow", function () {
		$("#kotak").remove();
	  });    
	}, 3000);
	
});

function ajax_save_new_produk() {
    var form_data = $("form").serialize();
    if (document.getElementById("nama_produk").value != "") {
        $.ajax({
            type: "POST",
            url: "<?php echo site_url('backend/produk/ajax_save_new_product') ?>",
            data: form_data,
            success: function(return_data){
				window.location="<?php echo base_url();?>"+"backend/produk/edit/"+return_data;
			}
        });
    }
}

function brand_change()
{
	var brand_id = $("#prod_brand_id").val();
	var prod_kat_id = $("#prod_kat_id");
	var prod_kat_id_default = $("#prod_kat_id_default").val();
	var post_data = 'brand_id='+brand_id;
	prod_kat_id.html('<option>Loading..&nbsp;&nbsp;</option>');
	$.ajax({
		type: "POST",
		url: "<?php echo base_url().'backend/produk/get_kategori/' ?>"+prod_kat_id_default,
		data: post_data,
		success: function(return_data) {
			prod_kat_id.html(return_data);
		}
	});
}

function expand_this(hidden_div)
{
	$("#"+hidden_div).slideToggle(300);
	return false;
}

function get_harga_jual()
{
	var harga_distributor = $("#harga").val();
	var persen_diskon = $("#persen_diskon").val();
	var val = (harga_distributor - ( harga_distributor * persen_diskon / 100 ));
	$("#harga_jual").attr("value",val);
}

function show_upload_box(id,look)
{
	if(id==''){
		id = $("#produk_id").val();
	}
	$.fancybox({
		'type': 'ajax',
		'padding': 0,
		'href': '<?php echo base_url().'backend/produk/upload_image/';?>'+id+'/'+look
	});
}

</script>

<style type="text/css">
      #kotak {
        width: 250px;
        height: 20px;
      }
</style>
<div class="left"></div>
<div class="right"></div>
<div class="heading">
	<h1 style="background-image: url('<?php echo base_url()?>assets/images/product.png');">Katalog</h1>
</div>
<div class="yui-gc wrapper">
<h1>Tambah Produk</h1>
<?php echo $this->session->flashdata('message_type');?>
<form id="add_product_form" action="" method="post" enctype="multipart/form-data">
    <div class="yui-u first">
        <fieldset>
		<legend>Product</legend>
		<ul>
			<li>
				<label for="nama_produk">Nama</label>
				<?php echo form_error('nama_produk', '<div class="error">', '</div>'); ?>
				<input id="nama_produk" type="text" name="nama_produk" class="title" value="" onblur="ajax_save_new_produk()">
			</li>
			<li>
				<label for="kode_produk">Kode Produk</label>
				<?php echo form_error('kode_produk', '<div class="error">', '</div>'); ?>
				<input id="kode_produk" type="text" name="kode_produk" class="text" value="">
			</li>
			<li>
				<label for="deskripsi">Deskripsi</label>
				<?php echo form_error('deskripsi', '<div class="error">', '</div>'); ?>
				<textarea id="deskripsi" name="deskripsi"></textarea>
			</li>
			<li>
				<label for="deskripsi_promo">Deskripsi Promo</label>
				<?php echo form_error('deskripsi_promo', '<div class="error">', '</div>'); ?>
				<textarea id="deskripsi_promo" name="deskripsi_promo"></textarea>
			</li>
			<li class="gambar hidden">
				<label for="image">Gambar</label>
				<div style="width:630px;display:block;clear:both;float:left;overflow:auto;">
					<div class="img-produk border-box">
						<span class="img-header">TAMPAK DEPAN</span>
						<div class="img-container border-box">
							<?php echo get_produk_image(FALSE,'1');?>
						</div>
					</div>
					<div class="img-produk border-box">
						<span class="img-header">TAMPAK SAMPING</span>
						<div class="img-container border-box">
							<?php echo get_produk_image(FALSE,'2');?>
						</div>
					</div>
					<div class="img-produk border-box">
						<span class="img-header">TAMPAK BELAKANG</span>
						<div class="img-container border-box">
							<?php echo get_produk_image(FALSE,'3');?>
						</div>
					</div>
				</div>
            </li>
			<li>
				<div style="display:block;height:40px;width:100%;clear:both;float:left;"></div>
			</li>
		</ul>
		</fieldset>
    </div>
	
<div class="yui-u">
	<fieldset>
		<legend>Detail Produk</legend>
		<ul>
			<li>
				<label for="prod_brand_id">Vendor / Manufaktur</label>
				<?php echo form_error('prod_brand_id', '<div class="error">', '</div>'); ?>
				<?php echo vendorDropdown();?>
			</li>
			<li>
				<label for="prod_kat_id">Kategori</label>
				<?php echo form_error('prod_kat_id', '<div class="error">', '</div>'); ?>
				<input type="hidden" id="prod_kat_id_default" name="prod_kat_id_default" value="0">
				<select id='prod_kat_id' name='prod_kat_id' class='contact_input' style="width:300px;">;
					<?php echo produk_category_dropdown('1', '0',FALSE);?>
				</select>
			</li>
			<li>
				<label for="harga">Harga Distributor</label>
				<?php echo form_error('harga', '<div class="error">', '</div>'); ?>
				<input type="text" id="harga" name="harga" class="text" value="0" onkeyup="get_harga_jual();">
			</li>
			<li>
				<label for="persen_diskon">Persen Diskon</label>
				<input type="text" id="persen_diskon" name="persen_diskon" class="text" value="0" onkeyup="get_harga_jual();">
			</li>
			<li>
				<label for="harga_jual">Harga Jual</label>
				<input type="text" id="harga_jual" name="harga_jual" class="text" value="0" readonly="readonly">
			</li>
			<li>
				<label for="qty">Stok</label>
				<div style="width:100%;display:block;float:left;clear:both;">
				<?php echo produk_size_list();?>
				<br>
				</div>
			</li>
			<li>
				<label for="tersedia">Ketersediaan</label>
				<?php echo form_error('tersedia', '<div class="error">', '</div>'); ?>
				<?php echo booleanValueAva('Ya','tersedia')?>
			</li>
			<li>
				<label for="promo">Promo</label>
				<?php echo form_error('promo', '<div class="error">', '</div>'); ?>
				<?php echo booleanValuePromo('Tidak','promo')?>
			</li>
			<li>
				<label for="status">Status</label>
				<?php echo form_error('status', '<div class="error">', '</div>'); ?>
				<?php echo booleanValueStatus('n','status')?>
			</li>
			<li>
				<input id="produk_id" type="hidden" name="produk_id" value="">
				<input type="submit" value="Simpan"> atau <?php echo anchor('backend/produk','Batalkan')?>
			</li>
		</ul>
	</fieldset>
</div>
</form>
</div>